<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<title>内部管理系统</title>
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">

<link rel="stylesheet" type="text/css" href="../../lib/bootstrap/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="../../stylesheets/theme.css">
<link rel="stylesheet" href="../../lib/font-awesome/css/font-awesome.css">

<script src="../../lib/jquery.min.js" type="text/javascript"></script>
<script src="../../lib/bootstrap/js/bootstrap.js"></script>
<script src="../../lib/jquery.validate.min.js"></script>
<script src="../../lib/jquery.cookie.js"></script>
<script src="../../lib/jquery.messager.js"></script>
<script src="../../js/init.js"></script>

<!-- <script src="../../lib/jquery.min.js" type="text/javascript"></script>
<script src="../../lib/bootstrap/js/bootstrap.js"></script>
<script src="../../lib/jquery.validate.min.js"></script>
<script src="../../lib/jquery.cookie.js"></script>
<script src="../../lib/jquery.messager.js"></script>
<script src="../../js/init.js"></script>

<link rel="stylesheet" href="//apps.bdimg.com/libs/jqueryui/1.10.4/css/jquery-ui.min.css">
<script src="//apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//apps.bdimg.com/libs/jqueryui/1.10.4/jquery-ui.min.js"></script> -->

<style type="text/css">
#container {
	height: 300px;
	width: 400px;
}

.fl {
	float: left
}

select {
	width: 130px;
}
.title{
	font-size:18px;
	font-weight:bold;
}
</style>
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
      <script src="lib/html5.js"></script>
    <![endif]-->
</head>

<!--[if lt IE 7 ]> <body class="ie ie6"> <![endif]-->
<!--[if IE 7 ]> <body class="ie ie7 "> <![endif]-->
<!--[if IE 8 ]> <body class="ie ie8 "> <![endif]-->
<!--[if IE 9 ]> <body class="ie ie9 "> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!-->
<body class="">
	<!--<![endif]-->

	<div class="navbar"></div>
	<div class="common"></div>

	<div class="sidebar-nav"></div>

	<div class="content">
		<div class="well">
			<ul class="nav nav-tabs">
				<li class="active"><a href="#userlist" data-toggle="tab">企业</a></li>
			</ul>
			<div id="myTabContent" class="tab-content">
				<div class="tab-pane active in" id="storelist">

					<div class="container-fluid">
						<div class="span8">
							<form class="form-horizontal" id="user_form">
								<div class="control-group title">详情 </div>
								<input type="hidden" id="companyId">
								<input type="hidden" id="provinceId_hidden">
								<input type="hidden" id="cityId_hidden">
								<input type="hidden" id="districtId_hidden">
								<input type="hidden" id="dicFieldId_hidden">

								<div class="control-group">
									<label class="control-label">企业名称：</label> 
									<label id="companyName"></label>
									<input type="text"  id="companyName_input" name="companyName_input" placeholder="企业名称">
								</div>
								<div class="control-group">
									<label class="control-label">领域：</label> 
									<select name="dicFieldId" id="dicFieldId"></select>
								</div>
								<div class="control-group">
									<label class="control-label">网址：</label> 
									<input type="text"  id="website" name="website" placeholder="网址">
								</div>
								<div class="control-group">
									<label class="control-label">地区：</label>
									<select name="provinceId" id="provinceId" onchange="loadCity()"></select>
									<select name="cityId" id="cityId" onchange="loadDistrict()"></select>
									<select name="districtId" id="districtId"></select>
								</div>
								<div class="control-group">
									<label class="control-label">地址：</label>
									<input type="text"  id="location" name="location" placeholder="地址">
								</div>
								<div class="control-group">
									<label class="control-label">邮箱：</label>
									<input type="text"  id="email" name="email" placeholder="邮箱">
								</div>
								<div class="control-group">
									<label class="control-label">电话：</label> 
									<label id="tel"></label>
									<input type="text"  id="tel_input" name="tel_input" placeholder="电话">
								</div>
								<div class="control-group">
									<label class="control-label">简介：</label>
									<input type="text"  id="intro" name="intro" placeholder="简介">
								</div>

								<div class="form-actions">
									<button id="btn-back" type="button" class="btn ">返回</button>
									<button id="btn-save" type="button" class="btn ">保存</button>
								</div>

							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>


	<script type="text/javascript">
	
		//初始化导航栏
		$(function() {
			initAdminNavBar();
			initCommon();
			initSideBar('user-management', 'company-list');
		});
		
		//初始化页面信息
		function onload(){
			var companyId = getparastr('companyId');
			
			if (companyId != null && companyId != "") {//更新的情况下,给页面赋初始值
				 $('#companyName_input').hide();
				 $('#tel_input').hide();
			}else{//新增
				$('#companyName').hide();
				$('#tel').hide();
			}
			$.ajax({
				contentType : "application/json",
				url : api_base_url1
						+ "open/dic/selectCompanyField.json",
				dataType : "json",
				success : function(data) {
					if (data.code == "200") {
						var options = "<option value='0'>请选择</option>";

						for (var int = 0; int < data.responseData.length; int++) {
							options += "<option value='" + data.responseData[int].dicFieldId
									+ "'>" + data.responseData[int].dicFieldName
									+ "</option> ";
						}
						$('#dicFieldId').html(options);
						var dicFieldId_hidden = $('#dicFieldId_hidden').val();
						$("#dicFieldId").val(dicFieldId_hidden);
					}
				}
			});
			$.ajax({
				contentType : "application/json",
				url : api_base_url1
						+ "open/dic/selectDistrictList.json?level=1",
				dataType : "json",
				success : function(data) {
					if (data.code == "200") {
						var options = "<option value='0'>请选择</option>";

						for (var int = 0; int < data.responseData.length; int++) {
							options += "<option value='" + data.responseData[int].dicDistrictId
									+ "'>" + data.responseData[int].dicDistrict
									+ "</option> ";
						}
						$('#provinceId').html(options);
						var provinceId_hidden = $('#provinceId_hidden').val();
						$("#provinceId").val(provinceId_hidden); 
					}
				}
			});
			var provinceId_hidden = $('#provinceId_hidden').val();
			if(provinceId_hidden != null && provinceId_hidden != ""){
				loadCity(provinceId_hidden);
			}
			var cityId_hidden = $('#cityId_hidden').val();
			if(cityId_hidden != null && cityId_hidden != ""){
				loadDistrict(cityId_hidden);
			}
		}
		
		function loadCity(provinceId_hidden){
			var provinceId = $('#provinceId').val();
			if(provinceId == null || provinceId == ""){
				provinceId = provinceId_hidden;
			}
		     $("#cityId").empty();
		     $("#districtId").empty();
		     $.ajax({
					contentType : "application/json",
					url : api_base_url1
							+ "open/dic/selectDistrictList.json?level=2&parentId=" + provinceId,
					dataType : "json",
					success : function(data) {
						if (data.code == "200") {
							var options = "<option value='0'>请选择</option>";

							for (var int = 0; int < data.responseData.length; int++) {
								options += "<option value='" + data.responseData[int].dicDistrictId
								+ "'>" + data.responseData[int].dicDistrict
										+ "</option> ";
							}
							$('#cityId').html(options);
							var cityId_hidden = $('#cityId_hidden').val();
							$("#cityId").val(cityId_hidden);
						}
					}
				});
		}
		
		function loadDistrict(cityId_hidden){
			var cityId = $('#cityId').val();
			if(cityId == null || cityId == ""){
				cityId = cityId_hidden;
			}
		     $("#districtId").empty();
		     $.ajax({
					contentType : "application/json",
					url : api_base_url1
							+ "open/dic/selectDistrictList.json?level=3&parentId=" + cityId,
					dataType : "json",
					success : function(data) {
						if (data.code == "200") {
							var options = "<option value='0'>请选择</option>";

							for (var int = 0; int < data.responseData.length; int++) {
								options += "<option value='" + data.responseData[int].dicDistrictId
								+ "'>" + data.responseData[int].dicDistrict
										+ "</option> ";
							}
							$('#districtId').html(options);  
							var districtId_hidden = $('#districtId_hidden').val();
							$("#districtId").val(districtId_hidden);
						}
					}
				});
		}
		
		//初始化用户详细信息
		$(function() {
			var companyId = getparastr('companyId');
			$("#companyId").html(companyId);
			if (companyId != null && companyId != "") {//更新的情况下,给页面赋初始值
				$.ajax({
					contentType : "application/json",
					url : api_base_url
							+ "selectCompanyDetail.json?companyId="
							+ companyId,
					dataType : "json",
					success : function(data) {
						if (data.code == "200") {
							var provinceId = data.responseData.provinceId;
							var cityId = data.responseData.cityId;
							var districtId = data.responseData.districtId;
							var cityStr = data.responseData.cityStr;
							var location = data.responseData.location;
							var website = data.responseData.website;
							var companyName = data.responseData.companyName;
							var createDate = data.responseData.createDate;
							var dicFieldId = data.responseData.dicFieldId;
							var email = data.responseData.email;
							var intro = data.responseData.intro;
							var tel = data.responseData.tel;
							$("#companyId").val(companyId);
							$("#provinceId").html(provinceId);
							$("#provinceId_hidden").val(provinceId);
							$("#cityId").html(cityId);
							$("#cityId_hidden").val(cityId);
							$("#districtId").html(districtId);
							$("#districtId_hidden").val(districtId);
							$("#location").val(location);
							$("#website").val(website);
							$("#companyName").html(companyName);
							$("#dicFieldId").val(dicFieldId);
							$("#dicFieldId_hidden").val(dicFieldId);
							$("#email").val(email);
							$("#intro").val(intro);
							$("#tel").html(tel);
							onload();
						}
						$.messager.anim('fade', 1000);
					    $.messager.show('操作提示',data.msg, 5000);
					}
				
				});
			}else{
				onload();
			}

		});


		//返回
		$('#btn-back').on('click', function() {
			history.back()
		});
		
		//保存
		$('#btn-save').on('click', function() {
			var companyId = $('#companyId').val();
			var companyName = '';
			var tel = '';
			if (companyId == null || companyId == "") {//更新的情况下,给页面赋初始值
				companyName = $('#companyName_input').val();
				tel = $('#tel_input').val();
			}
			var districtId = $('#districtId').val();
			var location = $('#location').val();
			var website = $('#website').val();
			var dicFieldId = $('#dicFieldId').val();
			var email = $('#email').val();
			var intro = $('#intro').val();
			
			$.ajax({
				contentType : "application/json",
				url : api_base_url
						+ "editCompany.json?companyId=" + companyId
						+ "&companyName=" + companyName
						+ "&districtId=" + districtId
						+ "&location=" + location
						+ "&website=" + website
						+ "&dicFieldId=" + dicFieldId
						+ "&email=" + email
						+ "&intro=" + intro
						+ "&tel=" + tel,
				dataType : "json",
				success : function(data) {
					/* if (data.code == "200") {
						window.location.href="../usermanagement/companylist.html";
					}else{
						
					} */
						$.messager.anim('fade', 1000);
					    $.messager.show('操作提示',data.msg, 5000);
					
				}
			});
		});


		
	</script>

</body>
</html>


